package com.project.service.gradeService.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.project.bean.GradeBean;
import com.project.bean.RoleBean;
import com.project.mapper.gradeMapper.IRoleMapper;
import com.project.service.gradeService.IRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class RoleServiceImpl implements IRoleService {
    @Autowired
    IRoleMapper roleMapper;

    @Override
    public PageInfo<RoleBean> findAll(int pageNO) {
        PageHelper.startPage(pageNO,PAGESIZE);
        PageInfo<RoleBean> pageInfo = PageInfo.of(roleMapper.findAll());
        return pageInfo;
    }
    @Override
    public List<RoleBean> findAllRole(){
        return roleMapper.findAll();
    }

    @Override
    public void add(RoleBean roleBean, int[] gradeId) {
        roleMapper.add(roleBean);
        roleMapper.addRoleGrade(roleBean.getId(),gradeId);
    }

    @Override
    public void del(int id) {
        roleMapper.delRoleGrade(id);
        roleMapper.delRoleUser(id);
        roleMapper.del(id);
    }

    @Override
    public RoleBean findById(int id) {
        return roleMapper.findById(id);
    }

    @Override
    public void update(int id,int[] gradeId) {
        roleMapper.delRoleGrade(id);
        roleMapper.addRoleGrade(id, gradeId);
    }

    @Override
    public List<GradeBean> findGrade(int[] roleId) {
        return roleMapper.findGrade(roleId);
    }
}
